import pandas as pd
import tkinter
from tkinter import *

#read file
file="C:/Users/宋/Desktop/STEM_project/Program/Items_Info.csv"
filedata=pd.read_csv(file)
file2 = "C:/Users/chen/Desktop/STEM_project/Program/NewItems.csv"
itemdata2 = pd.read_csv(file2)

#select an item
def selection(b):
    for i in range(len(filedata)):
        if filedata['Product_Name'][i] == b:
            cost = filedata['Cost'][i]
            price = filedata['Price'][i]
            quantity = filedata['Quantity'][i]
            return cost,price,quantity
            break

def selection2(b):
    for i in range(len(filedata2)):
        if filedata2['Product_Name'][i] == b:
            cost = filedata2['Cost'][i]
            price = filedata2['Price'][i]
            quantity = filedata2['Quantity'][i]
            return cost,price,quantity
            break



#shelves
def shelves():
    file1 = "C:/Users/chen/Desktop/STEM_project/Program/Items.csv"
    itemdata = pd.read_csv(file1)

    num = [0 for i in range(5)]
    shelf = [[''for j in range(10)for k in range(4)]]

    for a in range(5):
        num[a] = a+1
        shelfNum = num[a]
        for b in range(40):
            shelf[b] = itemdata['Product_Name']

        print(shelfNum)

l = shelves()

def profit(c):
    C,P,Q = selection(c)
    return (P-C)*Q

def profit2(c):
    C,P,Q = selection2(c)
    return (P-C)*Q
    
def getprofit():
    profits1 = []
    for d in range(40):
            profits.append(profit(shelf[d]))
    profits2 = []
    newItem = []
    for f in range(20):
        newItem[f] =itemdata2['Product_Name']
        profits2.append(profit2(newItem[f]))
        
getprofit()



def judge():
    g = profits1.index(min(profits1))
    if profits[g]<max(profits2):
        cost,price,quantity = selection2(newItem[profits2.index(max(profits2))])
        shelf[g]=newItem[profits2.index(max(profits2))]
        Dataset = list(zip(profits2.index(max(profits2)),cost,price,quantity))
        df = pd.DataFrame(data = Dataset,columns = ['Product_Name','Cost','Price','Quantity'])
        df.to_csv("C:/Users/chen/Desktop/STEM_project/Program/Dataset(random).csv",index = False,header = False)
        profits2.remove(max(profits2))
        return true
    return false

while judge():
    judge()

            




def payment():
    pass

root = TK()
root.config(bg="palegoldenrod")

lbl = Label(root,text="Please choose a payment",font=("Arial Bold",50),hustify=CENTER).please(x=40,y=0)
wechat = Button(root,text="Wechat Pay",height=2,width=12,bg="green",font=("Arial Bold",40),
                anchor="center",command=payment).place(x=450,y=200,anchor="center")
ali = Button(root,text="Ali Pay",height=2,width=12,bg="blue",fg="white",font=("Arial Bold",40),
             anchor="center",command=payment).place(x=450,y=400,anchor="center")
card = Button(root,text="Credit Card",height=2,width=12,bg="red",fg="yellow",font=("Arial Bold",40),
              anchor="center",command=payment).place(x=450,y=600,anchor="center")   
root.mainloop()

#要写函数对应每个button和label，在command里对应
photo = ImageTK.PhotoImage(file="C:/Users/宋/Desktop/STEM_project/Program/wechat.jpg")
label = Label(root,image=photo)
    











                
                
    
